/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.zimlet.ZimletPresence;
/*     */ import com.zimbra.cs.zimlet.ZimletUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.HashSet;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetZimletStatus
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  41 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  42 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  44 */     Element response = zsc.createElement(AdminConstants.GET_ZIMLET_STATUS_RESPONSE);
/*  45 */     Element elem = response.addElement("zimlets");
/*     */     
/*  47 */     List<Zimlet> zimlets = prov.listAllZimlets();
/*  48 */     zimlets = ZimletUtil.orderZimletsByPriority(zimlets);
/*  49 */     int priority = 0;
/*  50 */     for (Zimlet z : zimlets)
/*     */     {
/*  52 */       if (hasRightsToList(zsc, z, Rights.Admin.R_listZimlet, null))
/*     */       {
/*     */ 
/*  55 */         doZimlet(zsc, context, z, elem, priority++);
/*     */       }
/*     */     }
/*  58 */     Iterator<Cos> cos = prov.getAllCos().iterator();
/*     */     
/*  60 */     while (cos.hasNext()) {
/*  61 */       Cos c = (Cos)cos.next();
/*     */       
/*     */ 
/*  64 */       if (hasRightsToListCos(zsc, c, Rights.Admin.R_listCos, needGetAttrsRight()))
/*     */       {
/*     */ 
/*  67 */         elem = response.addElement("cos");
/*  68 */         elem.addAttribute("name", c.getName());
/*  69 */         String[] z = ZimletUtil.getAvailableZimlets(c).getZimletNamesAsArray();
/*  70 */         for (int i = 0; i < z.length; i++)
/*  71 */           doZimlet(zsc, context, prov.getZimlet(z[i]), elem, -1);
/*     */       }
/*     */     }
/*  74 */     return response;
/*     */   }
/*     */   
/*     */   private void doZimlet(ZimbraSoapContext zsc, Map<String, Object> context, Zimlet z, Element elem, int priority) throws ServiceException
/*     */   {
/*  79 */     if (z == null) {
/*  80 */       return;
/*     */     }
/*     */     try
/*     */     {
/*  84 */       checkRight(zsc, context, z, Rights.Admin.R_getZimlet);
/*     */     } catch (ServiceException e) {
/*  86 */       if ("service.PERM_DENIED".equals(e.getCode())) {
/*  87 */         return;
/*     */       }
/*  89 */       throw e;
/*     */     }
/*     */     
/*  92 */     Element zim = elem.addElement("zimlet");
/*  93 */     zim.addAttribute("name", z.getName());
/*  94 */     zim.addAttribute("status", z.isEnabled() ? "enabled" : "disabled");
/*  95 */     zim.addAttribute("extension", z.isExtension() ? "true" : "false");
/*  96 */     if (priority >= 0) {
/*  97 */       zim.addAttribute("priority", priority);
/*     */     }
/*     */   }
/*     */   
/*     */   private Set<String> needGetAttrsRight() {
/* 102 */     Set<String> attrsNeeded = new HashSet();
/* 103 */     attrsNeeded.add("zimbraZimletAvailableZimlets");
/* 104 */     return attrsNeeded;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 109 */     relatedRights.add(Rights.Admin.R_listZimlet);
/* 110 */     relatedRights.add(Rights.Admin.R_listCos);
/* 111 */     relatedRights.add(Rights.Admin.R_getZimlet);
/*     */     
/* 113 */     notes.add("Only zimlets on which the authed admin has effective " + Rights.Admin.R_listZimlet.getName() + " and " + Rights.Admin.R_getZimlet.getName() + " rights will appear in <zimlets> in the response.");
/*     */     
/*     */ 
/*     */ 
/* 117 */     notes.add("Only zimlets on which the authed admin has effective " + Rights.Admin.R_listCos.getName() + " right will be appear in <cos> in the response.");
/*     */     
/*     */ 
/*     */ 
/* 121 */     notes.add("e.g. there are zimlet1, zimlet2, zimlet3 and cos1, cos2 , if an admin has effective " + Rights.Admin.R_listZimlet.getName() + " and " + Rights.Admin.R_getZimlet.getName() + " rights on zimlet1, zimlet2, " + "then only zimlet1, zimlet2 will appear in <zimlets> in GetZimletStatusResponse, " + "and only cos1 will appear in <cos> in the resposne.  " + "The GetZimletStatusRequest itself will not get PERM_DENIED.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetZimletStatus.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */